package com.ruoyi.web.controller.ring;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.ora.constant.BizConstants;
import com.ruoyi.ring.factory.AiFactory;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ring.domain.RingSleep;
import com.ruoyi.ring.service.IRingSleepService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 睡眠Controller
 * 
 * @author liuwp
 * @date 2025-08-18
 */
@RestController
@RequestMapping("/ring/ring_sleep")
public class RingSleepController extends BaseController
{
    @Autowired
    private IRingSleepService ringSleepService;

    /**
     * 查询睡眠列表
     */
    @PreAuthorize("@ss.hasPermi('ring:ring_sleep:list')")
    @GetMapping("/list")
    public TableDataInfo list(RingSleep ringSleep)
    {
        // TODO  ai调用方式
//        String s = AiFactory.build(BizConstants.AI_PLATFORM.getValue()).chatCompletions("xxxxxx, 请给以上描述打一个0-5的分数，请直接返回分数，不要其他任何内容");



        startPage();
        List<RingSleep> list = ringSleepService.selectRingSleepList(ringSleep);
        return getDataTable(list);
    }

    /**
     * 导出睡眠列表
     */
    @PreAuthorize("@ss.hasPermi('ring:ring_sleep:export')")
    @Log(title = "睡眠", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RingSleep ringSleep)
    {
        List<RingSleep> list = ringSleepService.selectRingSleepList(ringSleep);
        ExcelUtil<RingSleep> util = new ExcelUtil<RingSleep>(RingSleep.class);
        util.exportExcel(response, list, "睡眠数据");
    }

    /**
     * 获取睡眠详细信息
     */
    @PreAuthorize("@ss.hasPermi('ring:ring_sleep:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ringSleepService.selectRingSleepById(id));
    }

    /**
     * 新增睡眠
     */
    @PreAuthorize("@ss.hasPermi('ring:ring_sleep:add')")
    @Log(title = "睡眠", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RingSleep ringSleep)
    {
        return toAjax(ringSleepService.insertRingSleep(ringSleep));
    }

    /**
     * 修改睡眠
     */
    @PreAuthorize("@ss.hasPermi('ring:ring_sleep:edit')")
    @Log(title = "睡眠", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RingSleep ringSleep)
    {
        return toAjax(ringSleepService.updateRingSleep(ringSleep));
    }

    /**
     * 删除睡眠
     */
    @PreAuthorize("@ss.hasPermi('ring:ring_sleep:remove')")
    @Log(title = "睡眠", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ringSleepService.deleteRingSleepByIds(ids));
    }
}
